﻿namespace PrismEx.Fixtures
{
    using System;
    using System.Reflection;

    using FluentAssertions;

    using Microsoft.Practices.Prism.Events;

    using NUnit.Framework;

    using PrismEx.Events;
    using PrismEx.Fixtures.Steps;

    using StoryQ;

    /*
Scenario: Subscriber exists before event is published
	Given an event has been subscribed to
	When an event is published
	Then the subscription delegate should have been called 1 times

Scenario: Subscriber does not exist before event is published
	Given an event has not been subscribed to
	When an event is published
	And an event has been subscribed to
	Then the subscription delegate should have been called 1 times

Scenario: Event published after event is unsubscribed from
	Given 
	When an event is published
	And the event is unsubscribed from
	And an event is published
	Then the subscription delegate should have been called 1 times*/


    [TestFixture]
    public class QueuedEventsFixture
    {
        private IEventAggregator eventAggregator = new EventAggregator();
        private int delegateCallCount;
        

        [Test]
        public void SubscriberExistsBeforeEvent()
        {
            SubscriptionToken subscriptionToken;
            Action anEventHasBeenSubscribedTo = () => subscriptionToken = eventAggregator.Subscribe<QueuedEventSteps.FakeQueuedEvent>(e => delegateCallCount++);
            Action whenAnEventIsPublished = () => eventAggregator.Publish<QueuedEventSteps.FakeQueuedEvent>(); ;
            Action<int> theSubscriptionDelegateShouldHaveBeenCalled_Times = i => delegateCallCount.Should().Be(i); ;

            new Story("Queued Events")
                .InOrderTo("Prevent loss of events")
                .AsA("Event subscriber")
                .IWant("Events to be queued until I subscribe")
                .WithScenario("Queuing Events before any subscriptions")
                .Given(anEventHasBeenSubscribedTo)
                .When(whenAnEventIsPublished)
                .Then(theSubscriptionDelegateShouldHaveBeenCalled_Times, 1)
                .ExecuteWithReport(MethodBase.GetCurrentMethod());
        }
    }
}